package com.hy.mvc.biz.excel.enums;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;

/**
 * Created by Booker on 2017/7/3.
 */
public enum CellType {
    CELL_TYPE_NUMERIC(0) {
        @Override
        public Object convertCell(Cell cell) {
            if (DateUtil.isCellDateFormatted(cell)) {
                return cell.getDateCellValue();
            }
            return (Double) cell.getNumericCellValue();
        }
    },
    CELL_TYPE_STRING(1) {
        @Override
        public Object convertCell(Cell cell) {
            return cell.getStringCellValue();
        }
    },
    CELL_TYPE_FORMULA(2) {
        @Override
        public Object convertCell(Cell cell) {
            return cell.getCellFormula().toString();
        }
    },
    CELL_TYPE_BOOLEAN(4) {
        @Override
        public Object convertCell(Cell cell) {
            return (Boolean) cell.getBooleanCellValue();
        }
    };

    private int type;

    private CellType(int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public abstract Object convertCell(Cell cell);
}
